import { useUserStore } from '@/stores/user'
export default {
    install(app) {
        app.directive('permission', {
            mounted(el, bingding) {
                // hasPermission(bingding.value,el)

            
                const value = bingding.value;
                const store = useUserStore();
            //    console.log(store.permission,"====") 
                //这里是因为页面刷新后加载完毕后才会设置store 导致permission是空的 采取监听的方式
                watch(() => store.permission, (newData) => {
                    const hasAuth = value.findIndex(value => newData.includes(value)) != -1;
                    if (el && !hasAuth) {
                        el.parentNode && el.parentNode.removeChild(el)
                    }
                })

                // const hasAuth = value.findIndex(value => store.permission.includes(value)) != -1;
                // if (el && !hasAuth) {
                //     el.parentNode && el.parentNode.removeChild(el)
              //  }
            },
        
        })
    }
}